package com.jinunn.user.controller;

import com.atguigu.yygh.model.user.UserInfo;
import com.atguigu.yygh.vo.user.LoginVo;
import com.atguigu.yygh.vo.user.UserAuthVo;
import com.jinunn.common.result.Result;
import com.jinunn.common.utils.AuthContextHolder;
import com.jinunn.user.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author JinDun
 * @date 2021/5/11 22:42
 */
@Api(tags = "登录")
@RestController
@RequestMapping("api/user")
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation("用户手机号登录接口")
    @PostMapping("login")
    public Result<Map<String,Object>> loginUser(@RequestBody LoginVo loginVo){
        Map<String,Object> map = userInfoService.loginUser(loginVo);
        return Result.ok(map);
    }

    @ApiOperation("用户认证接口")
    @PostMapping("auth/userAuth")
    public Result<UserInfo> userAuth(@RequestBody UserAuthVo userAuthVo, HttpServletRequest request){
        userInfoService.userAuth(userAuthVo, AuthContextHolder.getUserId(request));
        return Result.ok();
    }

    @ApiOperation("获取用户信息详情")
    @GetMapping("getUserDetail")
    public Result<UserInfo> getUserDetail(HttpServletRequest request){
        UserInfo userInfo = userInfoService.getUserDetail(request);
        return Result.ok(userInfo);
    }
}
